package com.lfs.market.controller.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lfs.market.model.R;
import com.lfs.market.model.dto.UserAdminPageDto;
import com.lfs.market.model.entity.User;
import com.lfs.market.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/web/user")
@SaCheckLogin
@SaCheckRole(value = {"admin", "check"}, mode = SaMode.OR)
public class UserAdminController {
    @Autowired
    private UserService userService;

    /**
     * 查询用户列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public R<Page<User>> getUserList(UserAdminPageDto dto) {

        Page<User> page = userService.getUserList(dto);
        return R.ok(page);
    }

    /**
     * 启用账号
     *
     * @param userId
     * @return
     */
    @PutMapping("/able/{id}")
    public R ableUser(@PathVariable("id") String userId) {
        userService.ableUser(userId);
        return R.ok();
    }

    /**
     * 管理员禁用用户
     *
     * @param userId
     * @return
     */
    @PutMapping("/disable/{id}")
    public R disableUser(@PathVariable("id") String userId) {
        userService.disableUser(userId);
        return R.ok();
    }


    /**
     * 修改个人资料 审核成功
     *
     * @param userId
     * @return
     */
    @PutMapping("/check/success/{id}")
    public R success(@PathVariable("id") String userId) {
        userService.success(userId);

        return R.ok();
    }

    /**
     * 修改个人资料 审核失败
     *
     * @param
     * @return
     */
    @PutMapping("/check/fail/{id}")
    public R fail(@PathVariable("id") String userId) {
        userService.fail(userId);

        return R.ok();
    }
}
